<?php
class news_edit extends SClass {

    public function process() {
        try {
            $news = ServiceUtils::GetFactory()->getNewsService()->getNewsById($this->getArgument('id'));
            if ($this->getControlValue('save')) {
            	ServiceUtils::GetFactory()->getNewsService()->editNews(
            	   $news->getId(),
            	   $this->getControlValue('title'),
            	   $this->getControlValue('preview'),
            	   $this->getControlValue('content')
            	);
            	$this->assign('message', 'ok');
            } else {
                $this->setControlValue('title', $news->getTitle());
                $this->setControlValue('preview', $news->getPreview());
                $this->setControlValue('content', $news->getContent());
            }
        } catch (ServiceUtils_Exception $exception) {
            $this->assign('errors', $exception->getErrors());
        }
    }

}